<?php
namespace Pw\MainBundle\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
class Guide
{
	private $id;
	private $authorId;
	private $title;
	private $votesPro;
	private $votesCon;
	private $moderated;
	private $toModeration;
	private $visible;
	private $views;
	private $dateCreated;

	private $author;
	private $chapters;
//	private $comments;
	public function __construct() {
		$this->chapters = new ArrayCollection();
//		$this->comments = new ArrayCollection();
		$this->votesPro = 0;
		$this->votesCon = 0;
		$this->views = 0;
		$this->moderated = false;
		$this->visible = false;
	}

	public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
//		$metadata->addConstraint(new UniqueEntity(array('fields' => 'name', 'groups' => array('add'))));
//		$metadata->addPropertyConstraint('icon', new Assert\Image(array(
//			'maxSize' => '1024k',
//			'mimeTypesMessage' => 'Please upload a valid image (1MB max)',
//        )));
//		$metadata->addPropertyConstraint('art', new Assert\Image(array(
//			'maxSize' => '1024k',
//			'mimeTypesMessage' => 'Please upload a valid image (1MB max)',
//        )));
//		//Name
//		$metadata->addPropertyConstraint('name', new Assert\NotBlank());
//        $metadata->addPropertyConstraint('name', new Assert\Length(array("max" => 100)));
	}


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set authorId
     *
     * @param integer $authorId
     * @return Guide
     */
    public function setAuthorId($authorId)
    {
        $this->authorId = $authorId;
    
        return $this;
    }

    /**
     * Get authorId
     *
     * @return integer 
     */
    public function getAuthorId()
    {
        return $this->authorId;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Guide
     */
    public function setTitle($title)
    {
        $this->title = $title;
    
        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Get rating
     *
     * @return integer 
     */
    public function getRating()
    {
		$rating = $this->votesPro - $this->votesCon;
		if ($rating > 0) {
			return $rating;
		}
        return 0;
    }

    /**
     * Set visible
     *
     * @param boolean $visible
     * @return Guide
     */
    public function setVisible($visible)
    {
        $this->visible = $visible;
    
        return $this;
    }

    /**
     * Get visible
     *
     * @return boolean 
     */
    public function getVisible()
    {
        return $this->visible;
    }

    /**
     * Set moderated
     *
     * @param boolean $moderated
     * @return Guide
     */
    public function setModerated($moderated)
    {
        $this->moderated = $moderated;
    
        return $this;
    }

    /**
     * Get moderated
     *
     * @return boolean 
     */
    public function getModerated()
    {
        return $this->moderated;
    }

    /**
     * Set dateCreated
     *
     * @param \DateTime $dateCreated
     * @return Guide
     */
    public function setDateCreated($dateCreated)
    {
        $this->dateCreated = $dateCreated;
    
        return $this;
    }

    /**
     * Get dateCreated
     *
     * @return \DateTime 
     */
    public function getDateCreated()
    {
        return $this->dateCreated;
    }

    /**
     * Add chapters
     *
     * @param \Pw\MainBundle\Entity\Chapter $chapters
     * @return Guide
     */
    public function addChapter(Chapter $chapters)
    {
		$chapters->setGuide($this);
        $this->chapters[] = $chapters;
        return $this;
    }

    /**
     * Remove chapters
     *
     * @param \Pw\MainBundle\Entity\Chapter $chapters
     */
    public function removeChapter(Chapter $chapters)
    {
        $this->chapters->removeElement($chapters);
    }

    /**
     * Get chapters
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getChapters()
    {
        return $this->chapters;
    }

    /**
     * Set votesPro
     *
     * @param integer $votesPro
     * @return Guide
     */
    public function setVotesPro($votesPro)
    {
        $this->votesPro = $votesPro;
    
        return $this;
    }

    /**
     * Get votesPro
     *
     * @return integer 
     */
    public function getVotesPro()
    {
        return $this->votesPro;
    }

    /**
     * Set votesCon
     *
     * @param integer $votesCon
     * @return Guide
     */
    public function setVotesCon($votesCon)
    {
        $this->votesCon = $votesCon;
    
        return $this;
    }

    /**
     * Get votesCon
     *
     * @return integer 
     */
    public function getVotesCon()
    {
        return $this->votesCon;
    }

    /**
     * Set views
     *
     * @param integer $views
     * @return Guide
     */
    public function setViews($views)
    {
        $this->views = $views;
    
        return $this;
    }

    /**
     * Get views
     *
     * @return integer 
     */
    public function getViews()
    {
        return $this->views;
    }

    /**
     * Set author
     *
     * @param \Pw\AccessBundle\Entity\User $author
     * @return Guide
     */
    public function setAuthor(\Pw\AccessBundle\Entity\User $author = null)
    {
        $this->author = $author;
    
        return $this;
    }

    /**
     * Get author
     *
     * @return \Pw\AccessBundle\Entity\User 
     */
    public function getAuthor()
    {
        return $this->author;
    }
}